home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Shareware World
/
Utilities
/
Text Processing
/
Alpha
/
Tcl
/
UserCode
/
canon.tcl
< prev
next >
Wrap
Text File
|
1996-08-15
|
4KB
|
164 lines
# FILE: canon.tcl
#
# LAST UPDATED: 12/07/92 6:37:34 AM
#
# This file contains the following TCL procedure(s):
#
# canon -- forces identifiers to canonical form
# SYNOPSIS:
#
# Canonize identifiers
#
# DESCRIPTION:
#
# Searches & replaces identifiers with new/corrected spelling.
# May be used to force language keywords to a particular alphabetic
# case. Simplifies ensuring case consistency.
#
# Advantages of using this procedure over simple search/replace
# are:
#
# A. Defaults to word boundary replacements
# B. Batch operation
# C. Forces alphabetic case
#
# INSTRUCTIONS:
#
# Simply:
# 1. Create several lines with the old and new words. List may
# start with # treated as a comment. Example:
#
# oldName newName
#
# 2. Select lines containing old and new words.
# 3. Invoking canon will change EVERY occurence. Example:
#
# newName newName
#
# 4. If you want the original text back, it is saved in the named clipboard
# called "canon-text"
#
# Options:
#
# -a = any occurence of oldName (not restricted to word boundaries)
# -c = case insensitive
# -r = use regular expressions
#
# If any line in the list has a single word only, then the canonization
# forces any case insensitive version of that word to the specific case.
# COPYRIGHT:
#
# Copyright © 1992 by David C. Black
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by David C. Black.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
################################################################################
# AUTHOR
#
# David C. Black
# Internet: black@mpd.tandem.com (preferred)
# GEnie: D.C.Black
# USnail: 6217 John Chisum Lane, Austin, TX 78749
#
################################################################################
# HISTORY
#
# modified who rev reason
# -------- --- --- ------
# 12/03/92 DCB 1.0 Original
################################################################################
proc canon {args} {
global searchStr
global replaceStr
global ignoreCase
global regExpr
global forward
global ignoreCase
global matchWords
shadowVar regExpr
shadowVar forward
shadowVar ignoreCase
shadowVar matchWords
saveVars
if {[getPos] == [selEnd]} {
alertnote "Nothing selected"
return
}
watchCursor
set regExpr 0
set forward 1
set ignoreCase 0
set matchWords 1
foreach arg $args {
case $arg {
{-a} {
set matchWords 0
}
{-c} {
set ignoreCase 1
}
{-r} {
set regExpr 1
}
}
}
# Get the canonical text list
beginningLineSelect
endLineSelect
set text [getSelect]
clear
# Save copy
global clipBoards
enableMenuItem Misc "pasteNamedClipboard" on
set clipBoards(canon-text) $text
set lines [split $text "\r"]
# Split the text list into a proper TCL list
foreach line $lines {
regsub "^#" $line "" line
set line [string trim $line]
regsub "\[ \t\]+" $line " " line
set bullet [split $line]
case [llength $bullet] {
{2} {
lappend bullet $ignoreCase
lappend ammo $bullet
}
{1} {
lappend ammo [list $bullet $bullet 1]
}
}
}
# Do the work
foreach pair $ammo {
set searchStr [lindex $pair 0]
set replaceStr [lindex $pair 1]
set ignoreCase $ignoreCase
goto 0
searchRall
}
restoreVars
}
#endproc canon
################################################################################